package cn.yilongquan.controller;

import cn.yilongquan.exception.BusinessException;
import cn.yilongquan.system.RO.LoginRO;
import cn.yilongquan.service.LoginInfoService;
import cn.yilongquan.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 登录相关控制器
 * 仅包含登录和注销两个核心接口
 */
@RestController
@RequestMapping("/login")
public class LoginController {

    @Autowired
    private LoginInfoService loginInfoService;

    /**
     * 用户登录接口
     */
    @PostMapping
    public R login(@RequestBody LoginRO loginRO) {

        //是否有请求数据
        if(loginRO.getUsername() == null || loginRO.getPassword() == null){
            throw new BusinessException("账号密码不能为空");
        }
        return loginInfoService.login(loginRO);
    }
}
